﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MvcBase
{
    public class BaseObjectContext
    {
        /// <summary>
        /// Gets the object by id.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context">The context.</param>
        /// <param name="id">The id.</param>
        /// <returns>Object</returns>
        public static T GetObjectById<T>(ObjectContext context, int id) where T : EntityObject
        {
            var objList = context.CreateObjectSet<T>().ToList();
            T obj = null;
            foreach (var item in objList)
            {
                if (item.EntityKey.EntityKeyValues[0].Value.Equals(id))
                {
                    obj = item;
                }
            }
            return obj;
        }
    }
}
